﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.Instances;

namespace Bookkeeping.Persistence.Conventions
{
    public class ClassConvention : IClassConvention
    {
        public void Apply(IClassInstance instance)
        {
            string className = instance.EntityType.Name;

            // "Category" should get the table name "categories", not "categorys"
            if (className.EndsWith("y"))
                instance.Table(className.Remove(className.Length - 1) + "ies");
            else
                instance.Table(className + "s");
        }
    }
}
